<!-- 自定义顶部导航【带返回】 -->
<template>
	<view class="bg">
		<view class="top_nav_return">
			<view class="top_nav_title">
				历年真题
				<view class="imgbox" >
					<image src="../../../static/icon/arrow_l_white.png" mode=""></image>
					<view class="returnbox" @tap="backPage()"></view>
				</view>
			</view>
		</view>
		<view class="content" v-if="lnzt_list.length > 0">
			<view class="list" v-for="(item,index) in lnzt_list" :key="index" @click="onParsing(item)">
				<view class="list_l">
					<view class="text"> {{item.paperName}} </view>
					<view class="tip" v-if="item.isLastHole == 1"> 继续做 </view>
				</view>
				<view class="list_r">
					<span class="text1">
						<span v-if="item.doNumber == null">0</span>
						<span v-else-if="item.doNumber == 0">{{item.doNumber != null ? item.doNumber : ''}}</span>
						<span style="color:#0191A0;"
							v-else-if="item.doNumber > 0 && item.doNumber < item.allNumber">{{item.doNumber != null ? item.doNumber : ''}}</span>
						<span v-else>{{item.doNumber != null ? item.doNumber : ''}}</span>
						/
						<span>{{item.allNumber != null ? item.allNumber : ''}}</span>
					</span>
					<img src="../../../static/icon/arrow_r_1.png" alt="">
				</view>
			</view>
		</view>
		<view class="list_end" v-if="lnzt_list.length > 0"> —— 到底了 —— </view>
		<img src="../../../static/icon/question_nodata.png" alt="" class="nodata_tip" v-else>
		<view v-show='loginAss' class="back-tankuang">
			<login class="loginw" @guanbi='guanbi' />
		</view>
	</view>
</template>

<script>
	import {
		get_lnzt_list,
		get_lnzt_listById
	} from '@/api/index/lnzt.js'
	import {
		getToken,
		getMajorInfo,
		setlistById,
		getlistById,
		setchapter,
		getchapter,
		setpaper
	} from '@/common/util/index.js'
	import {
		checkLoginState
	} from '@/api/login.js'
	export default {
		data() {
			return {
				lnzt_list: [],
				loginAss: getApp().globalData.loginAss,
				imageUrls: getApp().globalData.imaeWd,
			}
		},
		onLoad() {
			this.get_lnzt_list()
		},
		methods: {
			guanbi(value) {
				this.loginAss = value
			},
			onParsing(item) {
				if (!getToken()) {
					// uni.showToast({
					// 	title: '请先登录',
					// 	icon: 'error',
					// 	duration: 2000
					// })
					this.loginAss = true
				} else {
					checkLoginState().then((res) => {
						console.log('登陆状态：', res);
						setpaper(item)
						uni.navigateTo({
							url: '/pages/index/answerSheet?sourceType=2'
						})
					}).catch((err) => {
						console.log('err：', err);
						if (err.data.code == 401 && err.data.message == "账号在其他设备登录") {
							// uni.showToast({
							// 	title: '登录过期',
							// 	icon: 'error',
							// 	duration: 2000
							// })
							this.loginAss = true;
						}
					})
				}
			},
			get_lnzt_list() {
				let data = {
					appId: uni.getAccountInfoSync().miniProgram.appId,
					// appId:'wxa1a230d527c944e7',
					majorId: getMajorInfo().id
				}
				get_lnzt_list(data).then((res) => {
					console.log('历年真题列表获取:', res);
					this.lnzt_list = res.result
				}).catch((err) => {
					console.log(err);
				})
			},
			backPage() {
				uni.reLaunch({
					url: '/pages/index/index'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.nodata_tip{
		position: fixed;
		top:50%;
		left:50%;
		transform: translate(-50%,-50%);
	}
	.list_end {
		padding: 50rpx 0;
		// padding-bottom: 50rpx;
		height: 50rpx;
		line-height: 50rpx;
		text-align: center;
		color: #ccc;
		font-size: 30rpx;
	}

	.bg {
		// overflow: hidden;
		box-sizing: border-box;
		padding-top: 200rpx;
		min-height: 100vh;
		background: rgba(249, 249, 249, 0.8);
	}

	.list {
		margin: 0 30rpx;
		padding: 40rpx 0;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1rpx solid #EEEEEE;
	}

	.list_l {
		display: flex;
		align-items: center;

		.text {
			margin-right: 30rpx;
			max-width: 350rpx;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: bold;
		}

		.tip {
			width: 99rpx;
			height: 35rpx;
			text-align: center;
			line-height: 35rpx;
			color: #fff;
			font-size: 22rpx;
			font-family: PingFang SC;
			font-weight: 500;
			background-image: url('../../../static/icon/doing.png');
			background-size: cover;
		}
	}

	.list_r {
		font-size: 28rpx;
		font-family: Bahnschrift;
		font-weight: normal;
		display: flex;
		align-items: center;

		.text1 {
			margin-right: 40rpx;

			span {
				margin-right: 3rpx;
			}
		}

		img {
			width: 16rpx;
			height: 28rpx;
		}
	}

	.content {
		overflow: hidden;
		margin: 0 30rpx;
		background: #fff;
		border-radius: 20rpx;
	}

	.returnbox {
		position: absolute;
		top: -15rpx;
		left: -15rpx;
		height: 60rpx;
		width: 70rpx;
	}

	.top_nav_return {
		position: fixed;
		z-index: 10;
		top: 0;
		left: 0;
		width: 100vw;
		padding-top: 90rpx;
		padding-bottom: 30rpx;
		background-color: #0191A0;
		color: #fff;
	}

	.top_nav_title {
		position: relative;
		text-align: center;
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: bold;
	}

	.imgbox {
		position: absolute;
		z-index: 10;
		top: 0;
		left: 30rpx;
		height: 36rpx;
		display: flex;
		justify-content: start;

		image {
			height: 36rpx;
			width: 19rpx;
		}
	}
</style>
